From cb7d3eed4823f0670e8f7b887d210eda4df8c939 Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 30 Jan 2004 20:00:43 +0000 Subject: [PATCH] Let GPX parse geocaching-specific descriptions & hints. Add string to decompse UTF to ASCII. --- gpsbabel/defs.h | 4 ++++ gpsbabel/gpx.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 8df876115..46a13ed55 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -101,6 +101,9 @@ typedef struct { int diff; /* (multiplied by ten internally) */ int terr; /* (likewise) */ time_t exported; + char *hint; /* all these UTF8, XML entities removed, May be not HTML. */ + char *desc_short; + char *desc_long; } geocache_data ; @@ -389,6 +392,7 @@ signed int get_tz_offset(void); const char *get_cache_icon(const waypoint *waypointp); char * xml_entitize(const char * str); char * str_utf8_to_cp1252( const char * str ); +char * str_utf8_to_ascii( const char * str ); /* * PalmOS records like fixed-point numbers, which should be rounded diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 7dff24541..627e51b9a 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -39,6 +39,7 @@ static char *gpx_author = NULL; vmem_t current_tag; static waypoint *wpt_tmp; +static int cache_descr_is_html; static FILE *fd; static FILE *ofd; static void *mkshort_handle; @@ -79,6 +80,9 @@ typedef enum { tt_cache_container, tt_cache_difficulty, tt_cache_terrain, + tt_cache_hint, + tt_cache_desc_short, + tt_cache_desc_long, tt_cache_log_wpt, tt_rte, tt_rte_name, @@ -142,6 +146,9 @@ tag_mapping tag_path_map[] = { { tt_cache_container, 1, "/gpx/wpt/groundspeak:cache/groundspeak:container" }, { tt_cache_difficulty, 1, "/gpx/wpt/groundspeak:cache/groundspeak:difficulty" }, { tt_cache_terrain, 1, "/gpx/wpt/groundspeak:cache/groundspeak:terrain" }, + { tt_cache_hint, 1, "/gpx/wpt/groundspeak:cache/groundspeak:encoded_hints" }, + { tt_cache_desc_short, 1, "/gpx/wpt/groundspeak:cache/groundspeak:short_description" }, + { tt_cache_desc_long, 1, "/gpx/wpt/groundspeak:cache/groundspeak:long_description" }, { tt_cache_log_wpt, 1, "/gpx/wpt/groundspeak:cache/groundspeak:logs/groundspeak:log/groundspeak:log_wpt" }, { tt_rte, 0, "/gpx/rte" }, @@ -248,6 +255,21 @@ tag_wpt(const char **attrv) } } +static void +tag_cache_desc(const char ** attrv) +{ + const char **avp; + + cache_descr_is_html = 0; + for (avp = &attrv[0]; *avp; avp+=2) { + if (strcmp(avp[0], "html") == 0) { + if (strcmp(avp[1], "True") == 0) { + cache_descr_is_html = 1; + } + } + } +} + static void start_something_else(const char *el, const char **attrv) { @@ -404,6 +426,11 @@ gpx_start(void *data, const char *el, const char **attr) case tt_cache_log_wpt: if (opt_logpoint) tag_log_wpt(attr); + break; + case tt_cache_desc_long: + case tt_cache_desc_short: + tag_cache_desc(attr); + break; } if (passthrough) { start_something_else(el, attr); @@ -574,6 +601,24 @@ gpx_end(void *data, const char *el) sscanf(cdatastrp, "%f", &x); wpt_tmp->gc_data.diff = x * 10; break; + case tt_cache_hint: + rtrim(cdatastrp); + if (cdatastrp[0]) { + wpt_tmp->gc_data.hint = xstrdup(cdatastrp); + } + break; + case tt_cache_desc_long: + rtrim(cdatastrp); + if (cdatastrp[0]) { + wpt_tmp->gc_data.desc_long = xstrdup(cdatastrp); + } + break; + case tt_cache_desc_short: + rtrim(cdatastrp); + if (cdatastrp[0]) { + wpt_tmp->gc_data.desc_short = xstrdup(cdatastrp); + } + break; case tt_cache_terrain: sscanf(cdatastrp, "%f", &x); wpt_tmp->gc_data.terr = x * 10; -- 2.30.2